package com.example.springboottest.big3.annotation;

import org.springframework.beans.factory.annotation.Value;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * 请求路径是 curl http://localhost:9090/first
 *
 * 其实@WebServlet、@WebFilter、@WebListener注解与SpringBoot没有关系，
 * 它们都属于JavaWeb编程的基础知识。在传统Web应用中，只要为Web组件添加这些注解，Web容器（如Tomcat）就会自动发现它们，
 * 并将它们注册为Web应用中的组件。接下来只要为AppConfig类添加@ServletComponentScan注解，
 * 告诉SpringBoot去扫描`注册这些Web组件即可。
 *
 */

@WebServlet("/first")
public class FirstAnnotationServlet extends HttpServlet {
    @Value("${spring.user.name}")
    private String greeting;

    @Override
    public void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        log("----FirstServlet---");
        resp.setContentType("text/html");
        resp.setCharacterEncoding("utf-8");
        PrintWriter out = resp.getWriter();
        out.println("FirstAnnotationServlet，信息：欢迎您\t" + greeting);
    }
}
